import urllib.request

# 百度翻译API
url = 'https://fanyi.baidu.com/sug'
header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36'
}
data = {
    'kw': 'spider'
}
# POST编码必须再编码，转成字节数据
data = urllib.parse.urlencode(data).encode('UTF-8')

# POST请求参数不凭借GET参数
request = urllib.request.Request(url=url, headers=header, data=data)
response = urllib.request.urlopen(request)
result = response.read().decode('UTF-8')
print(result)
